package com.qlk.test.vorder.rest;

import java.util.Date;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;

import com.qlk.common.client.AbstractClient;
import com.qlk.common.utils.config.PropertiesHelper;
import com.qlk.common.utils.security.MD5Util;
import com.qlk.common.utils.serialize.JsonHelper;
import com.qlk.test.vorder.rest.dto.Orders;
import com.qlk.test.vorder.rest.response.OrdersResponse;
import com.qlk.test.vorder.rest.Urls;
import com.qlk.vorder.domain.enums.OrderCancelEnum;
import com.qlk.vorder.domain.enums.OrderStatusEnum;
import com.qlk.vorder.sdk.api.request.OrdersRequest;
import com.qlk.vorder.sdk.api.request.OrdersRequestDto;
import com.qlk.vorder.sdk.api.request.ReserveSessionRequestDto;
import com.qlk.vorder.service.OrdersService;

/**
 * OrdersResource单元测试
 * 
 * @author zhaoyanan
 * @version 2016-7-28 14:14:01
 * 
 */
public class OrdersResourceTestCase extends AbstractClient {
	@Autowired
	private OrdersService ordersService;

	@Test
	public void testGetOrders() {
		String url = Urls.API_DOMAIN + "/orders/getOrders";

		OrdersRequest request = new OrdersRequest();
		request.setId(1l);
		OrdersResponse response = super.getRestTemplate().postForObject(url, request, OrdersResponse.class);
		Assert.notNull(response);
		Orders orders = super.getResult(response);
		Assert.notNull(orders);
	}

	@Test
	public void testOrderData() {
		RestTemplate restTemplate = new RestTemplate();
		String url = "http://127.0.0.1:8080/qlk-vorder-webservice/services/orders/orderData";

		OrdersRequestDto request = new OrdersRequestDto();
		request.setOrderid("V00132016072200003");
		request.setOrderStatus(OrderStatusEnum.CANCEL.getType());
		request.setTimestamp(new Date());
		request.setSign(MD5Util.md5Hex(request.getOrderid() + PropertiesHelper.newInstance().getValue("vorder.task.sign")));
		OrdersRequest ordersRequest = new OrdersRequest();
		ordersRequest.setCancelDescribe(OrderCancelEnum.DR_GQWZX.getType());
		ordersRequest.setCancelName("asd");
		ordersRequest.setConditionDescribe("d");
		ordersRequest.setDrId("a");
		ordersRequest.setDrName("ads");
		ordersRequest.setIsRefund(0);
		ordersRequest.setOrderid("123");
		ordersRequest.setOrderPrice("12.21");
		ordersRequest.setOrderStatus(OrderStatusEnum.WAIT_PAY.getType());
		// ordersRequest.setOrderTime(new Date());
		ordersRequest.setPatientAge(20);
		ordersRequest.setPatientId("2");
		ordersRequest.setPatientMobile("123-");
		ordersRequest.setPatientSex(1);
		ordersRequest.setPatientName("12");
		ordersRequest.setPayStatus(1);
		ordersRequest.setPayType(4);
		request.setOrder(ordersRequest);
		String json = JsonHelper.toJson(request);
		System.out.println(json);
		String response = restTemplate.postForObject(url, request, String.class);
		System.out.println(response + "<<<<<<<<<<<<<<<<<<<<<<");
	}

	@Test
	public void testOrderSession() {
		RestTemplate restTemplate = new RestTemplate();
		String url = "http://10.9.1.197:8080/qlk-vorder-webservice/services/orders/sessionData";

		ReserveSessionRequestDto request = new ReserveSessionRequestDto();
		// request.setSessionId(1);
		request.setOrderid("123456");
		request.setSign(MD5Util.md5Hex(request.getOrderid() + PropertiesHelper.newInstance().getValue("vorder.task.sign")));
		request.setStartTime(new Date());
		request.setEndTime(new Date());
		request.setTimeLength("6");
		String json = JsonHelper.toJson(request);
		System.out.println(json);
		String response = restTemplate.postForObject(url, request, String.class);
		System.out.println(response + "<<<<<<<<<<<<<<<<<<<<<<");
	}
	
	@Test
	public void testRefund() {
		ordersService.createRefundTask("V00132016072200003");
	}

}
